<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>7-案例：封装一个函数返回年月日时分秒</title>
	</head>
	<body>
		<script type="text/javascript">
			function currentYmdHis(){
				var date = new Date();
				//获取年
					var year = date.getFullYear();
					//获取月份[0,11]
					var month = date.getMonth()+1;
					//获取哪一天
					var day = date.getDate();
					
					console.log(year+'='+month+'='+day);
					//星期几？
					var weeks = ['星期天','星期一','星期二','星期三','星期四','星期五','星期六'];
					var week = weeks[date.getDay()];
					console.log(week);
					
					var ymd = year+'年'+month+'月'+day+'日'+week;
					
					//时分秒
					var h = date.getHours();
					h = h<10 ? '0'+h : h;
					var i = date.getMinutes();
					i = i<10 ? '0'+i : i;
					var s = date.getSeconds();
					s = s<10 ? '0'+s : s;
					
					var his = h+'时'+i+'分'+s+'秒';
					
					return ymd+his;
				}
				
				var x = ymdhis();
				console.log(x);
			}
		</script>
	</body>
</html>
